package com.wpl.controller;

import com.wpl.bean.User;
import com.wpl.bean.Workorder;
import com.wpl.common.WebResponse;
import com.wpl.service.IOrderGroupService;
import org.apache.shiro.SecurityUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 本组工单
 */
@RestController
@RequestMapping("/orderGroup/")
public class OrderGroupController {

    @Resource
    private IOrderGroupService orderGroupService;

    /**
     * 本组工单
     * @return
     */
    @GetMapping("/all")
    public WebResponse allOrders(){
        User user = (User) SecurityUtils.getSubject().getSession().getAttribute("user");
        List<Workorder> workorders = orderGroupService.allOrders(user);
        if (!workorders.isEmpty()) {
            return WebResponse.success(workorders);
        }else {
            return WebResponse.failed();
        }
    }

    /**
     * 本组退单
     * @return
     */
    @GetMapping("/back")
    public WebResponse allBacks(){
        User user = (User) SecurityUtils.getSubject().getSession().getAttribute("user");
        List<Workorder> workorders = orderGroupService.allBacks(user);
        if (!workorders.isEmpty()){
            return WebResponse.success(workorders);
        }else {
            return WebResponse.failed();
        }
    }
}
